﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Rhsoft.SqlServer.MetadataManager
{
    public partial class Options : Form
    {
        public Options( )
        {
            InitializeComponent( );
            LoadSettings( );
        }

        #region Methods
        void LoadSettings( )
        {
            fDescriptionName.Text = Properties.Settings.Default.DescriptionPropertyName;
            fIncludeSystemDb.Checked = Properties.Settings.Default.IncludeSystemDatabases;
            fOverride.Checked = Properties.Settings.Default.OverrideProperties;
            fSaveOnLostFocus.Checked = Properties.Settings.Default.SaveOnLostFocus;
            //
            fContextName.Text = Properties.Settings.Default.LqGenContextName;
            fContextNamespace.Text = Properties.Settings.Default.LqGenContextNamespace;
            fEntitiesNamespace.Text = Properties.Settings.Default.LqGenEntityNamespace;
            fSavePath.Text = Properties.Settings.Default.LqGenSavePath;
            fPreventDebug.Checked = Properties.Settings.Default.LqGenPreventDebug;
            fIsSealed.Checked = Properties.Settings.Default.LqGenIsSealed;
            fIsSerializable.Checked = Properties.Settings.Default.LqGenIsSerializable;
            fMultiple.Checked = Properties.Settings.Default.LqGenGenerateMultipleClasses;
            fSelectedTables.Checked = Properties.Settings.Default.LqGenOnlySelectedTables;
            fIncludeSystemTables.Checked = Properties.Settings.Default.IncludeSystemTables;
            fIncludeCRUD.Checked = Properties.Settings.Default.LqGenIncludeCRUD;
            fOverrideCRUD.Checked = Properties.Settings.Default.LqGenOverriteCRUD;
        }
        void SaveChanges( )
        {
            Properties.Settings.Default.DescriptionPropertyName = fDescriptionName.Text;
            Properties.Settings.Default.IncludeSystemDatabases = fIncludeSystemDb.Checked;
            Properties.Settings.Default.OverrideProperties = fOverride.Checked;
            Properties.Settings.Default.SaveOnLostFocus = fSaveOnLostFocus.Checked;
            //
            Properties.Settings.Default.LqGenContextName = fContextName.Text;
            Properties.Settings.Default.LqGenContextNamespace = fContextNamespace.Text;
            Properties.Settings.Default.LqGenEntityNamespace = fEntitiesNamespace.Text;
            Properties.Settings.Default.LqGenSavePath = fSavePath.Text;
            Properties.Settings.Default.LqGenPreventDebug = fPreventDebug.Checked;
            Properties.Settings.Default.LqGenIsSealed = fIsSealed.Checked;
            Properties.Settings.Default.LqGenIsSerializable = fIsSerializable.Checked;
            Properties.Settings.Default.LqGenGenerateMultipleClasses = fMultiple.Checked;
            Properties.Settings.Default.LqGenOnlySelectedTables = fSelectedTables.Checked;
            Properties.Settings.Default.IncludeSystemTables = fIncludeSystemTables.Checked;
            Properties.Settings.Default.LqGenOverriteCRUD = fOverrideCRUD.Checked;
            Properties.Settings.Default.LqGenIncludeCRUD = fIncludeCRUD.Checked;
            Properties.Settings.Default.Save( );
        }
        #endregion

        #region Events
        private void bCancel_Click( object sender, EventArgs e )
        {
            this.Hide( );
            this.Dispose( );
        }
        private void bOk_Click( object sender, EventArgs e )
        {
            this.Hide( );
            this.SaveChanges( );
            this.Dispose( );
        }
        private void bBrowse_Click( object sender, EventArgs e )
        {
            FolderBrowserDialog SvDialog = new FolderBrowserDialog( );
            if( SvDialog.ShowDialog( ) == DialogResult.OK )
            {
                fSavePath.Text = SvDialog.SelectedPath;
            }
        }

        #endregion

        
        
    }
}
